package com.magictower.primary.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.ndkjni.utils.NdkJniUtils;
import com.magictower.primary.R;
import com.magictower.primary.view.MyProgressBar;

public class MainActivity extends AppCompatActivity {

    // Used to load the 'ndkjni-lib' library on application startup.
    static {
        System.loadLibrary("ndkjni-lib");
    }

    private NdkJniUtils jniUtils;
    static private ProgressBar pb;
    static private MyProgressBar mpb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Example of a call to a native method
        jniUtils = new NdkJniUtils();

        pb = (ProgressBar) findViewById(R.id.pb);
        pb.setMax(100);

        mpb = (MyProgressBar) findViewById(R.id.mpb);
        mpb.setMax(100);

    }


    public void start(View v) {
        new Thread() {
            @Override
            public void run() {
                MainActivity.this.startMonitor();
            }
        }.start();
    }

    public void startFromUtils(View v) {
        new Thread() {
            @Override
            public void run() {
                jniUtils.startMonitorFromUtils();
            }
        }.start();
    }

    public void stop(View v) {
        this.stopMonitor();
    }

    public void test(View v) {
        Toast.makeText(this, jniUtils.stringFromJNI(), Toast.LENGTH_SHORT).show();
    }

    //提供给C++ JNI回调的JAVA方法
    public void show(int progress) {
        mpb.setPressure(progress);
        pb.setProgress(progress);
    }

    public native void startMonitor();
    public native void stopMonitor();

}
